package jp.co.jalinfotec.sxt.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/** Login request form */
public class OrderLunchActionForm extends ActionForm{

	/** Serial Version UID */
	private static final long serialVersionUID = 1L;
	
	/** User ID */
	private String userId;
	/** Password*/
	private String password;
	
	/**
	 * [Getter]User ID
	 * @return User ID
	 */
	public String getUserId() {return userId;}
	
	/**
     * [Setter]User ID
     * @param User ID
     */
	public void setUserId(String userId) {this.userId = userId;}

	/**
	 * [Getter]Password
	 * @return Password
	 */
	public String getPassword() {return password;}
	
	/**
	 * [Setter]Password
	 * @param password Password
	 */
	public void setPassword(String password) {this.password = password;}
	
	/** Default constructor. */
	public OrderLunchActionForm(){
		super();
	}
	
	/**
	 * Initialize Properties
	 * @param mapping Mapping info between URL and Action
	 * @param request Request
	 */
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.userId = null;
		this.password = null;
	}
	
	/**
	 * Validate input values. 
	 * TODO: Use MessageResources.
	 * @param mapping Mapping info between URL and Action
	 * @param request Request
	 */
	@Override
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		
		ActionErrors errors = new ActionErrors();
		
	    if (this.userId == null || this.userId.length() == 0) {
	        ActionMessage errorMessage =
	        	new ActionMessage("Input user ID.", false);
	        errors.add("user", errorMessage);
	    }
	    if (this.password == null || this.password.length() == 0) {
	        ActionMessage errorMessage =
	                new ActionMessage("Input password", false);
	        errors.add("password", errorMessage);
	    }

	    return errors; 
	}
}
